package com.acme.bankapp.domain.bank;

import java.util.Arrays;

public class Bank {
	static final String MES_REACH_MAX_CLIENT_COUNT = "Number of clients reaches max value";
	static final int MAX_CLIENT_COUNT = 10;
	
	private Client[] clients;
	private int clientCount;
	
	public Bank() {
		clients = new Client[MAX_CLIENT_COUNT];
		clientCount = 0;
	}
	
	@Deprecated
	public Bank(Client[] clients) {
		this();
		clientCount = clients.length > MAX_CLIENT_COUNT ? MAX_CLIENT_COUNT : clients.length;
		
		for (int i=0; i<clientCount; i++)
			this.clients[i] = clients[i];
	}
	
	public Client[] getClients() {
		return Arrays.copyOf(clients, clients.length);
	}
	
	public void addClient(Client client) throws ArrayIndexOutOfBoundsException {
		if (clientCount >= MAX_CLIENT_COUNT)
			throw new ArrayIndexOutOfBoundsException(MES_REACH_MAX_CLIENT_COUNT);
		
		clients[clientCount++] = client;
	}
}
